﻿using System;
using System.Threading;

namespace wires_as_objects
{
    class Wire<T> : IWire
    {
        private string _label;
        private int _delayMilliseconds;

        public Wire(){}
        public Wire(string label)
        {
            _label = label;
        }


        public void Process(T input)
        {
            if (this.Traceing) Console.WriteLine("{0}.Wire<{1}>: {2}", string.IsNullOrWhiteSpace(_label) ? "?" : _label, typeof(T).Name, input.ToString());

            if (_delayMilliseconds > 0) Thread.Sleep(_delayMilliseconds);

            this.Result(input);
        }

        public event Action<T> Result;


        public void Throttle(int delayMilliseconds)
        {
            _delayMilliseconds = delayMilliseconds;
        }


        public bool Traceing {get;set;}
    }
}